const cloud = require('wx-server-sdk')

cloud.init()

/// (skip: int = 0, limit: int = 20) -> (result: DbQueryResult<Book>)
exports.main = async (event) => {
  const skip = event.skip || 0;
  const limit = event.limit || 20;

  const db = cloud.database();
  const result = await db.collection('books').where({}).skip(skip).limit(limit).get();

  return {
    result: result
  };
}
